package com.tm.controller;

import com.tm.model.Serial;
import com.tm.service.SerialService;
import com.tm.util.RestReturnModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


@Api(tags = "天马-OA岗位 接口文档")
@RestController
@CrossOrigin
@RequestMapping("serial")
public class SerialController {

    @Autowired
    private SerialService serialService;

    @ApiOperation(value = "查询岗位管理树形结构集合",notes = "无需传参")
    @GetMapping("allService")
    public RestReturnModel allService(){
        return   RestReturnModel.SUCCESS(serialService.allService());
    }
    @ApiOperation(value = "新增岗位",notes = "需要传参数 Serial serial 但不需要Id")
    @PostMapping
    public RestReturnModel addDept(@RequestBody Serial serial){
            serialService.addSerialt(serial);
        return RestReturnModel.SUCCESS(null);
    }
    @ApiOperation(value = "修改岗位",notes = "需要传参数 Serial serial 但需要Id")
    @PutMapping
    public RestReturnModel updateData(@RequestBody Serial Serial){
            if(Serial.getId()!=Serial.getPid()) {
                serialService.updateSerial(Serial);
                return  RestReturnModel.SUCCESS(null);
            }
        return  RestReturnModel.ERROR();
    }
    @ApiOperation(value = "回显岗位",notes = "需要传参数")
    @ApiImplicitParam(name = "id",value = "主键Id",required = true,dataType = "number")
    @GetMapping("{id}")
    public RestReturnModel querySerialById(@PathVariable Integer id){

        return  RestReturnModel.SUCCESS(serialService.querySerialById(id));
    }
    @ApiOperation(value = "删除岗位",notes = "需要传参数")
    @ApiImplicitParam(name = "id",value = "主键Id",required = true,dataType = "number")
    @DeleteMapping("{id}")
    public RestReturnModel delDeptById(@PathVariable Integer id){
            serialService.delSerialById(id);
        return  RestReturnModel.SUCCESS(null);
    }
    @ApiOperation(value = "导出")
    @GetMapping("exportFile")
    public void exportFile(HttpServletResponse response ){
        serialService.exportFile(response);
    }
    @ApiOperation(value = "导入")
    @PostMapping ("uploadFile")
    public void uploadFile(MultipartFile dataFile) {
        serialService.uploadFile(dataFile);
    }

}
